package com.laan.plat;

import android.content.res.Resources;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.LightingColorFilter;
import android.graphics.Paint;
import android.util.Log;


public class Prota extends Pawn {
	
	public static int PROTAWIDTH = 48;
	public static int PROTAHEIGHT = 19*2;
	
	public static float PROTAJUMPSPEED = 10f;
	public static float PROTAMOVSPEED = 10f;
	
	public static float PROTAMAXAIRY = GV.Screen.metrics.heightPixels*2/3;
	public float maxAirY;
	
	public Paint paintColor;
	public boolean stateAir = false;
	
	public Prota(Resources res, float startx, float starty) {
		super(R.drawable.kirby_idle, R.drawable.kirby_walk, res, startx, starty, PROTAWIDTH, PROTAHEIGHT);
		sprWalk = new Sprite(BitmapFactory.decodeResource(resources, R.drawable.kirby_walk, options), 24, 19, 9, 9, 1, 5);
		getAndScaleFrames(true);
		maxAirY = 100;
	}

	@Override
	public void init() {
		super.init();
		GV.Game.prota = this;
		jumpspeed = PROTAJUMPSPEED;
		movspeed = PROTAMOVSPEED;
		paintColor = new Paint();
	}
	
	@Override
	public void actualitza() {
//		Log.i("prota", "actualitza");
		
//		Log.i("preActualitza", String.valueOf(vy));
		super.actualitza();
		GV.Game.offsetX = rec.centerX() - GV.Screen.metrics.widthPixels/2;
		
		if(stateAir) {
			ColorFilter filter = new LightingColorFilter(Color.rgb(64, 255, 255), 1);
			paintColor.setColorFilter(filter);
			g = 0;
			vy = -scale/PAWNMAXSCALE * jumpspeed;
//			float actMaxAirY = 1/scale * maxAirY;
			rec.offsetTo(rec.left, Math.max(rec.top, 0));
//			rec.offsetTo(rec.left, newY);
		}
		else {
			ColorFilter filter = new LightingColorFilter(Color.WHITE, 1);
			paintColor.setColorFilter(filter);
		}
//		Log.i("postActualitza", String.valueOf(vy));
	}
	
	public void hitEnemy(Pawn e) {
		if(rec.bottom <= e.rec.centerY()) {
//			Log.i("hitEnemy", String.valueOf(vy));
			e.die();
			jumpForced();
		}
		else die();
	}
	
	@Override
	public void draw(Canvas canvas) {
		draw(canvas, paintColor);
	}
	
	public void air() {
		stateAir = true;
	}
	
	public void normal() {
		vy = 0;
		stateAir = false;
	}

}
